package day_2022_12_to_3.year2023;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2023/02/09 22:20
 **/
public class Day2_9_Num1797 {
    class AuthenticationManager {
        int timeToLive =0;
        Map<String,Integer> map = new HashMap();
        public AuthenticationManager(int timeToLive) {
            this.timeToLive=timeToLive;
        }

        public void generate(String tokenId, int currentTime) {
            map.put(tokenId,currentTime);
        }

        public void renew(String tokenId, int currentTime) {
            for(Map.Entry<String,Integer> entry:map.entrySet()){
                if(entry.getKey().equals(tokenId)&&(entry.getValue()+timeToLive)>currentTime){
                    map.put(entry.getKey(),currentTime);
                }
            }
        }

        public int countUnexpiredTokens(int currentTime) {
            int size =0;
            for(Map.Entry<String,Integer> entry:map.entrySet()){
                if(entry.getValue()+timeToLive>currentTime){
                    size++;
                }
            }
            return size;
        }
    }
}